package com.etl.dataflow.executor.element;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

/**
 * @author dx
 * @since 2022/4/14
 */
public class TimestampColumn extends Column<Timestamp> {

    public TimestampColumn(String name, Timestamp timestamp, int jdbcType, String jdbcTypeName) {
        super(name, timestamp, jdbcType, jdbcTypeName);
    }

    @Override
    public String asString() {
        if (null == super.getValue()) {
            return null;
        }
        Date date = new Date(super.getValue().getTime());
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    }

    @Override
    public byte[] asBytes() {
        return new byte[0];
    }

    @Override
    public Timestamp asTimestamp() {
        return super.value;
    }

    @Override
    public Date asDate() {
        return null;
    }

    @Override
    public int getByteSize() {
        return 32;
    }
}
